home *** CD-ROM | disk | FTP | other *** search
/ A.C.E. 1 / ACE CD 1.iso / files / utils / rexxplus.dms / in.adf / RexxStub.a68 < prev    next >
Encoding:
Text File  |  1992-06-23  |  7.7 KB  |  206 lines

  1.     SECTION    _RexxStub,CODE
  2.     NOLIST
  3.     include 'exec/types.i'
  4.     include 'exec/execbase.i'
  5.     include 'rexx/storage.i'
  6.     include 'rexx/rxslib.i'
  7.     include 'libraries/dos.i'
  8.     include 'libraries/dosextens.i'
  9. _LVOOpenLibrary    EQU    -552
  10. _LVOInput    EQU    -54
  11. _LVOOutput    EQU    -60
  12.     LIST
  13.  
  14.     xdef    _RexxStub
  15.     xref    _sprintf,_RexxSysBase,_DOSBase
  16.  
  17. ;    Copyright © Dineen Edwards Group, Inc., 1987-91, All rigihts reserved
  18.  
  19. ;    This is a sample stub program to be used when interfacing C
  20. ;    and REXX PLUS Compiled programs. 
  21. ;    
  22. ;    The parameters are:
  23. ;        RoutinePtr        address of routine entry point 
  24. ;        BufferPtr        optional pointer to buffer
  25. ;        PatternPtr        pointer to pattern string for
  26. ;        Args            arguments as described by pattern
  27. ;
  28. ;    The subroutine calls sprintf to convert the parameters passed 
  29. ;    into string format for correct interpretation of the REXX PLUS
  30. ;    compiled program. It then breaks the parameters into arguments
  31. ;    and fills the RexxMsg with those arguments. It calls the routine
  32. ;    at the address pointed to by RoutinePtr, cleans up the Message,
  33. ;    and returns the result to the caller.
  34. ;
  35.              
  36. RexxRegs    reg    d1-d7/a0-a6
  37. BuffSize    equ    200
  38. ;RexxOff    equ    60+BuffSize+RM_SIZEOF
  39. RexxOff        equ    60+BuffSize+RMSIZEOF
  40.  
  41.     STRUCTURE    RexxStruct,RexxOff
  42.     APTR        RoutinePtr
  43.     APTR        BufferPtr
  44.     APTR        PatternPtr
  45.     APTR        Args
  46.     LABEL        SZ_RexxStruct
  47.  
  48. rexxlib    dc.b    "rexxsyslib.library",0,0
  49. doslib    dc.b    "dos.library",0
  50.  
  51. _RexxStub:
  52.     movem.l    d1-d7/a0-a6,-(sp)    ; /* save all registers, just incase */
  53.     move.l    $4,a6            ; /* get the exec library base */
  54. ;    sub.l    #RM_SIZEOF+BuffSize,sp    ; /* back up stack pointer */
  55.     sub.l    #RMSIZEOF+BuffSize,sp    ; /* back up stack pointer */
  56.     tst.l    _RexxSysBase        ; /* rexx base present? */
  57.     bne.s    RexxStubSkipOpen    ; /* yes, skip the open */
  58.     lea.l    rexxlib,a1        ; /* point to library */
  59.     move.l    #0,d0            ; /* set release number */
  60.     jsr    _LVOOpenLibrary(a6)    ; /* open the library */
  61.     move.l    d0,_RexxSysBase        ; /* fill in the pointer */
  62.     bne.s    RexxStubSkipOpen    ; /* skip the error */
  63.     move.l    #-1,d0            ; /* no library, return -1 */    
  64. ;    add.l    #RM_SIZEOF+BuffSize,sp    ; /* reset the pointer */
  65.     add.l    #RMSIZEOF+BuffSize,sp    ; /* reset the pointer */
  66.     movem.l    (sp)+,d1-d7/a0-a6    ; /* restore registers */
  67.     rts                ; /* return to caller */
  68.  
  69. RexxStubSkipOpen:
  70.     tst.l    _DOSBase        ; /* rexx base present? */
  71.     bne.s    RexxStubSkipDos        ; /* yes, skip the open */
  72.     lea.l    doslib,a1        ; /* point to library */
  73.     move.l    #0,d0            ; /* set release number */
  74.     jsr    _LVOOpenLibrary(a6)    ; /* open the library */
  75.     move.l    d0,_DOSBase        ; /* fill in the pointer */
  76.     bne.s    RexxStubSkipDos        ; /* skip the error */
  77.     move.l    #-1,d0            ; /* no library, return -1 */    
  78. ;    add.l    #RM_SIZEOF+BuffSize,sp    ; /* reset the pointer */
  79.     add.l    #RMSIZEOF+BuffSize,sp    ; /* reset the pointer */
  80.     movem.l    (sp)+,d1-d7/a0-a6    ; /* restore registers */
  81.     rts                ; /* return to caller */
  82.  
  83. RexxStubSkipDos:
  84.     move.l    BufferPtr(sp),d7    ; /* get buffer pointer */
  85.     bne.s    RexxStubNoAlloc        ; /* no, skip the allocate */
  86.     move.l    sp,d7            ; /* get the pointer */
  87. ;    add.l    #RM_SIZEOF,d7        ; /* point to the buffer */
  88.     add.l    #RMSIZEOF,d7        ; /* point to the buffer */
  89.  
  90. RexxStubNoAlloc:
  91.     move.l    #0,0(a7)        ; /* clear the message */
  92.     move.l    #0,4(a7)        ; /* clear the message */
  93.     move.l    #0,8(a7)            ; /* clear the message */
  94.     move.l    #0,12(a7)            ; /* clear the message */
  95.     move.l    #0,ARG0(a7)            ; /* clear Arg0 */
  96.     move.l    #0,rm_Result1(a7)        ; /* clear the result */
  97.     move.l    #0,rm_Result2(a7)        ; /* clear the result */
  98.     move.l    ThisTask(a6),rm_TaskBlock(a7)    ; /* get the task block */
  99.     move.l    _RexxSysBase,a0            ; /* get the rexx library */
  100.     move.l    rl_REXX(a0),LN_NAME(a7)        ; /* fill in the name */
  101.     add.l    #8,LN_NAME(a7)            ; /* point to the buffer */
  102.     move.l    LN_NAME(a7),rm_CommAddr(a7)    ; /* fill in the name */
  103.     move.l    LN_NAME(a7),rm_FileExt(a7)    ; /* fill in the name */
  104.     move.l    #0,MN_REPLYPORT(a7)        ; /* move in the port address */
  105.     move.l    #0,rm_PassPort(a7)        ; /* move in the port address */
  106.     move.l    _DOSBase,a6            ; /* get the dos base */
  107.     jsr    _LVOInput(a6)            ; /* get input file */
  108.     move.l    d0,rm_Stdin(a7)            ; /* save the input handle */
  109.     jsr    _LVOOutput(a6)            ; /* get output file */
  110.     move.l    d0,rm_Stdout(a7)        ; /* save the input handle */
  111.     move.l    #0,rm_avail(a7)            ; /* clear available */
  112.  
  113.     move.l    PatternPtr(a7),a1    ; /* get the pointer */
  114.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  115.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  116.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  117.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  118.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  119.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  120.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  121.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  122.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  123.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  124.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  125.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  126.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  127.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  128.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  129.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  130.     move.l    Args+16*4(a7),-(a7)    ; /* fill in the args */
  131.     pea.l    (a1)            ; /* push address on stack */
  132.     move.l    d7,-(sp)        ; /* put buffer on stack */
  133.     jsr    _sprintf        ; /* format the string */
  134.     add.l    #19*4,sp        ; /* reset the pointer */
  135.  
  136.     move.l    d7,a1            ; /* point to the string */
  137.     lea.l    Args(a7),a5        ; /* point to the list */
  138.     lea.l    ARG0(a7),a3        ; /* point to the list */
  139.     move.l    a1,(a3)+        ; /* fill in the pointer */
  140.     move.l    #0,d3            ; /* get the flags */
  141.  
  142. RexxStubPatLoop1:
  143.     move.b    (a1)+,d0        ; /* get the character */
  144.     beq.s    RexxStubPatEnd        ; /* end the loop */
  145.     cmp.b    #'"',d0            ; /* double? */
  146.     beq.s    RexxStubPatDouble    ; /* yes, handle it */
  147.     cmp.b    #$27,d0            ; /* single? */
  148.     beq.s    RexxStubPatSingle    ; /* yes, handle it */
  149.     cmp.b    #',',d0            ; /* next arg? */
  150.     bne    RexxStubPatLoop1    ; /* no, loop */
  151.     move.b    #0,-1(a1)        ; /* clear the byte */
  152.     move.l    a1,(a3)+        ; /* fill in the pointer */
  153.     cmp.l    #15,d3            ; /* count too large? */
  154.     bge.s    RexxStubPatEnd        ; /* yes, get out */
  155.     addq.l    #1,d3            ; /* increment the count */
  156.     bra    RexxStubPatLoop1    ; /* loop for next entry */
  157.  
  158. RexxStubPatDouble:
  159.     move.b    (a1)+,d0        ; /* get the character */
  160.     beq.s    RexxStubPatEnd        ; /* end the loop */
  161.     cmp.b    #'"',d0            ; /* double? */
  162.     bne    RexxStubPatDouble    ; /* no, handle it */
  163.     bra    RexxStubPatLoop1    ; /* loop for next character */
  164.  
  165. RexxStubPatSingle:
  166.     move.b    (a1)+,d0        ; /* get the character */
  167.     beq.s    RexxStubPatEnd        ; /* end the loop */
  168.     cmp.b    #$27,d0            ; /* single? */
  169.     bne    RexxStubPatSingle    ; /* no, handle it */
  170.     bra    RexxStubPatLoop1    ; /* loop for next character */
  171.  
  172. RexxStubPatEnd:
  173.     move.l    a7,a0            ; /* get the message pointer */
  174.     add.l    #RXFUNC,d3        ; /* say function */
  175.     move.l    d3,rm_Action(a0)    ; /* fill in count */
  176.     movea.l    _RexxSysBase,a6        ; /* get the rexx library */
  177.     move.l    d3,d0            ; /* get the count */
  178.     and.l    #15,d0            ; /* get the count */
  179.     addq.l    #1,d0            ; /* increment the count */
  180.     move.l    #0,d1            ; /* set the mask */
  181.     jsr    _LVOFillRexxMsg(a6)    ; /* get the arg string */
  182.  
  183.     move.l    a7,a0            ; /* get pointer for call */
  184.     move.l    RoutinePtr(a7),a6    ; /* get routine address */
  185.     jsr    (a6)            ; /* jump to the routine */
  186.     move.l    a0,a3            ; /* save the RexxMsg */
  187.     tst.l    d0            ; /* zero return code? */
  188.     beq.s    RexxStubZero        ; /* yes, return result string */
  189.     move.l    #0,a3            ; /* clear the result value */
  190.  
  191. RexxStubZero:
  192.     movea.l    _RexxSysBase,a6        ; /* get the rexx library */
  193.     move.l    a7,a0            ; /* get arg string zero */
  194.     move.l    rm_Action(a0),d0    ; /* get the count */
  195.     and.l    #15,d0            ; /* get the count */
  196.     addq.l    #1,d0            ; /* increment the count */
  197.     jsr    _LVOClearRexxMsg(a6)    ; /* get rid of the strings */
  198.  
  199.     move.l    a3,d0            ; /* get the result string */
  200. ;    add.l    #RM_SIZEOF+BuffSize,sp    ; /* reset the pointer */
  201.     add.l    #RMSIZEOF+BuffSize,sp    ; /* reset the pointer */
  202.     movem.l    (sp)+,d1-d7/a0-a6    ; /* restore registers */
  203.     rts                ; /* return to caller */
  204.  
  205.     end
  206.